package com.sc.VenusQueryBeta.ui.activites.login;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.hengjun.kingstar.sdk.base.BasePresenter;
import com.hengjun.kingstar.sdk.base.activity.BaseMVPCompatActivity;
import com.hengjun.kingstar.sdk.utils.SpUtils;
import com.hengjun.kingstar.sdk.utils.ToastUtils;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.contract.login.NextRegistContract;
import com.sc.VenusQueryBeta.global.MyApplication;
import com.sc.VenusQueryBeta.model.bean.login.ComfirmRegistrationBean;
import com.sc.VenusQueryBeta.model.bean.login.RegistBean;
import com.sc.VenusQueryBeta.model.bean.login.RegisterVerticationBean;
import com.sc.VenusQueryBeta.presenter.login.NextRegistPresenter;

import butterknife.BindView;
import butterknife.OnClick;


public class NextRegistActivity extends BaseMVPCompatActivity<NextRegistContract.NextPresenter> implements NextRegistContract.INextView {

    @BindView(R.id.next_back)
    ImageButton nextBack;
    @BindView(R.id.about_kingstar_infornation)
    AppBarLayout aboutKingstarInfornation;
    @BindView(R.id.et_next_password)
    EditText etNextPassword;
    @BindView(R.id.et_comfirm_new_password)
    EditText etComfirmNewPassword;
    @BindView(R.id.btn_comfirm_change)
    Button btnComfirmChange;

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return NextRegistPresenter.newInstance();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_next;
    }

    @OnClick({R.id.next_back, R.id.btn_comfirm_change})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.next_back:
                finish();
                break;
            case R.id.btn_comfirm_change: //直接註冊
                RegisterVerticationBean registerVerticationBean = SpUtils.getObject(MyApplication.app,RegisterVerticationBean.class);
                if (registerVerticationBean!=null) {
                    if (etNextPassword.getText().toString().trim().equals("") || etComfirmNewPassword.getText().toString().trim().equals("")) {
                        ToastUtils.showToast("密碼不能為空！");
                    } else {
                        if (etNextPassword.getText().toString().trim().equals(etComfirmNewPassword.getText().toString().trim())) {//兩次密碼輸入一樣
                            showProgressDialog("正在註冊........");
//                            if (registerVerticationBean.getAreaCode().equals("1")) {
//                                mPresenter.register(registerVerticationBean.getRegisterSmsnum(), "meg",
//                                        etNextPassword.getText().toString(), registerVerticationBean.getClientUID(), registerVerticationBean.getDeviceUID(), registerVerticationBean.getDeviceType(), registerVerticationBean.getAreaCode());
//                            } else {
                            mPresenter.register(registerVerticationBean.getRegisterSmsnum(),"meg",
                                    etNextPassword.getText().toString(), registerVerticationBean.getClientUID(), registerVerticationBean.getDeviceUID(), registerVerticationBean.getDeviceType(), registerVerticationBean.getAreaCode());
//                            }

                        } else {
                            ToastUtils.showToast("兩次密碼輸入不一樣！");
                        }
                    }
                }
                break;
        }
    }

    @Override
    public void returnRegistSuccess(RegistBean registBean) {
        //确认注册
        mPresenter.confirmRegister(registBean.getId(),"meg",registBean.getPassword(),registBean.getClientUID(),registBean.getDeviceUID(),registBean.getDeviceType());
    }

    @Override
    public void showNetworkError() {
        hideProgressDialog();
    }

    @Override
    public void returnConfirmRegistSuccess(ComfirmRegistrationBean comfirmRegistrationBean) {
        hideProgressDialog();
        ToastUtils.showToast("註冊成功");
//        ToastUtils.showToast("註冊成功="+comfirmRegistrationBean.getRegisterTime());
        finish();
    }
}
